<layout name="page" />
<block name="content">
	{:widget('page_header/search',array('name'=>'职级管理','search'=>'S'))}
	<div class="operate-panel">
		<div class="operate-panel-body">
			<div class="pull-right">
				<a onclick="add()" class="btn btn-normal">新增</a>
				<a id="btn_save" class="btn">保存</a>
				|
				<a onclick="del()" class="btn btn-del">删除</a>
			</div>
		</div>
	</div>
	<!-- 功能操作区域结束 -->
	<!-- 列表显示区域  -->
	<div class="row">
		<div class="col-sm-4 sub-sidebar ">
			<table class="table table-bordered">
				<thead>
					<tr>
						<th>名称</th>
						<th>状态</th>
					</tr>
				</thead>
				<tbody>
					<foreach name="list" val="data">
						<tr id="{$data.id}">
							<td>{$data.name}</td>
							<td>{$data.is_del|status}</td>
						</tr>
					</foreach>
				</tbody>
			</table>
		</div>
		<div class="input-block sub">
			<form id="form_data" name="form_data" method="post" >
				<input type="hidden" name="id" id="id">
				<input type="hidden" name="ajax" id="ajax" value="1">
				<input type="hidden" name="opmode" id="opmode" value="">
				<div class="layui-form-item col-xs-12">
					<label class="input-label" for="name">名称*：</label>
					
						<input class="input"  type="text" id="name" name="name" check="required" info="请输入名称">
					</div>
				</div>

				<div class="layui-form-item col-xs-12">
					<label class="input-label" for="sort">排序：</label>
					
						<input class="input"  type="text" id="sort" name="sort" >
					</div>
				</div>
				<div class="layui-form-item col-xs-12">
					<label class="input-label" for="is_del">状态：</label>
					
						<select  class="input" name="is_del" id="is_del">
							<option  value="0">启用</option>
							<option value="1">禁用</option>
						</select>
					</div>
				</div>
			</form>
		</div>
	</div>
</block>
<block name="js">
	<script type="text/javascript">
		function add() {
			$("#opmode").val("add");
			$("#id").val("");
			send_form("form_data", "{:url('save')}", "{:url('index')}");
		};

		function del() {
			var vars = $("#form_data").serialize();
			ui_confirm('确定要删除吗?', function() {
				send_ajax("{:url('del')}", vars, function(data) {
					if (data.status) {
						ui_alert(data.info, function() {
							location.reload(true);
						});
					}
				});
			});
		}

		function save() {
			send_form("form_data", "{:url('save')}", "{:url('index')}");
		}

		function show_data(result) {
			for (var s in result.data) {
				set_val(s, result.data[s]);
			}
			$("#opmode").val("edit");
		}


		$(document).ready(function() {
			set_return_url(null);
			$(".sub-sidebar tbody tr").click(function() {
				$(".sub-sidebar  tr.active").removeClass("active");
				$(this).attr("class", "active");
				send_ajax("{:url('read')}", "id=" + $(this).attr("id"), function(data) {
					show_data(data);
				});
				return false;
			});
		});
	</script>

</block>